home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / database / blt2rx_o.zip / SCRIPTS.ZIP / 04MIDD.CMD < prev    next >
OS/2 REXX Batch file  |  1996-08-05  |  13KB  |  338 lines

  1. /* 04 - data mid-level examples for Bullet/REXX */
  2. /* 3-Aug-96
  3.    Calls made in this example:
  4.    - blt_Init()
  5.    - blt_DeleteFileDos()   [to delete test-generated files]
  6.    - blt_CreateData()
  7.    - blt_OpenData()        [file-level locks used]
  8.    - blt_GetDescriptor()
  9.    - blt_AddRecord()
  10.    - blt_GetRecord()
  11.    - blt_UpdateRecord()
  12.    - blt_DeleteRecord()
  13.    - blt_UndeleteRecord()
  14.    - blt_DebumpRecord()
  15.    - blt_PackRecords()
  16.    - blt_CloseData()
  17.    - blt_Exit()
  18. */
  19.  
  20. /* Typically, each test routine's arg pack (blt_IP., etc.) is set to NOVALUE */
  21. /* so that any unset variables can easily be identified.  In actual use, */
  22. /* this would not be necessary since often arg pack values are already setup */
  23. /* for multiple calls, where blt_?P.variable is already properly set up */
  24.  
  25.  say "Example: 04midd.cmd  (recommend output be redirected to a file)"
  26.  
  27.  call RxFuncAdd 'BulletLoadFuncs', 'BREXXI2', 'BulletLoadFuncs'
  28.  call BulletLoadFuncs
  29.  
  30.  /* in case Bullet/REXX is still active, close it out */
  31.  
  32.  rez = blt_Exit()
  33.  
  34.  say
  35.  say "calling blt_Init()"
  36.  blt_IP.=NOVALUE
  37.  blt_IP.JFTsize=5       /* must be 5 */
  38.  rez = blt_Init()       /* init Bullet/REXX */
  39.  say " blt_IP.func is" blt_IP.func
  40.  say " blt_IP.stat is" blt_IP.stat  /* rez same as stat except for xactions */
  41.  if rez = 0 then do
  42.  
  43.     say " blt_IP.versionDOS is" blt_IP.versionDOS
  44.     say " blt_IP.versionOS is" blt_IP.versionOS
  45.     say " blt_IP.versionBullet is" blt_IP.versionBullet
  46.     /* say " blt_IP.exitPtr is" blt_IP.exitPtr */
  47.  
  48.     say
  49.     say "calling blt_DeleteFileDos() x2 (04MIDD.DB?)"
  50.     blt_DFP.=NOVALUE
  51.     blt_DFP.filename = "04MIDD.DBF"
  52.     rez = blt_DeleteFileDos();
  53.     say " blt_DFP.func is" blt_DFP.func
  54.     say " blt_DFP.stat is" blt_DFP.stat "(04MIDD.DBF) [stat=2, file not found, is possible]"
  55.  
  56.     blt_DFP.=NOVALUE
  57.     blt_DFP.filename = "04MIDD.DBT"  /* may use QuerySysVars for memo .EXT */
  58.     rez = blt_DeleteFileDos();
  59.     say " blt_DFP.stat is" blt_DFP.stat "(04MIDD.DBT)"
  60.  
  61.     say
  62.     say "calling blt_CreateData()"
  63.     blt_CDP.=NOVALUE
  64.     blt_CDP.filename = "04MIDD.DBF"
  65.     blt_CDP.noFields = 3
  66.     blt_CDP.FD.1.fieldName = "SSN"
  67.     blt_CDP.FD.1.fieldType = "N"
  68.     blt_CDP.FD.1.fieldLen = 9
  69.     blt_CDP.FD.1.fieldDC = 0
  70.     blt_CDP.FD.2.fieldName = "NAME"
  71.     blt_CDP.FD.2.fieldType = "C"
  72.     blt_CDP.FD.2.fieldLen = 10
  73.     blt_CDP.FD.2.fieldDC = 0
  74.     blt_CDP.FD.3.fieldName = "ADDR"
  75.     blt_CDP.FD.3.fieldType = "M"
  76.     blt_CDP.FD.3.fieldLen = 10
  77.     blt_CDP.FD.3.fieldDC = 0
  78.     blt_CDP.fileID = 139        /* memo, too  (139 is 0x8B [hex]) */
  79.     rez = blt_CreateData()      /* create data files: DBF and DBT */
  80.     say " blt_CDP.func is" blt_CDP.func
  81.     say " blt_CDP.stat is" blt_CDP.stat
  82.  
  83.     if rez = 0 then do
  84.        say
  85.        say "calling blt_OpenData()"
  86.        blt_OP.=NOVALUE
  87.        blt_OP.filename = blt_CDP.filename
  88.        blt_OP.asMode = 18       /* 18 is 0x0012 [hex] DENYRW, R/W */
  89.        rez = blt_OpenData()     /* see blt_Lock() for range locking */
  90.        say " blt_OP.func is" blt_OP.func
  91.        say " blt_OP.stat is" blt_OP.stat
  92.  
  93.        if rez = 0 then do
  94.           say " blt_OP.handle is" blt_OP.handle
  95.           say
  96.           say "calling blt_GetDescriptor()  [by field position, first descriptor]"
  97.           blt_DP.=NOVALUE
  98.           blt_DP.handle = blt_OP.handle
  99.           blt_DP.fieldNumber = 1
  100.           rez = blt_GetDescriptor()
  101.           say " blt_DP.func is" blt_DP.func
  102.           say " blt_DP.stat is" blt_DP.stat
  103.           if rez = 0 then do
  104.  
  105.              say " blt_DP.fieldNumber is" blt_DP.fieldNumber "(the following are for this)"
  106.              say " blt_DP.fieldOffset is" blt_DP.fieldOffset
  107.              say " blt_DP.FD.fieldName is '"blt_DP.FD.fieldName"'"
  108.              say " blt_DP.FD.fieldType is '"blt_DP.FD.fieldType"'"
  109.              say " blt_DP.FD.fieldLen is" blt_DP.FD.fieldLen
  110.              say " blt_DP.FD.fieldDC is" blt_DP.FD.fieldDC
  111.  
  112.              tmpStr = blt_DP.FD.fieldName
  113.              say
  114.              say "calling blt_GetDescriptor()  [by fieldName, using fieldname just gotten]"
  115.              blt_DP.=NOVALUE
  116.              blt_DP.handle = blt_OP.handle
  117.              blt_DP.fieldNumber = 0
  118.              blt_DP.FD.fieldName = tmpStr
  119.              rez = blt_GetDescriptor()
  120.              say " blt_DP.func is" blt_DP.func
  121.              say " blt_DP.stat is" blt_DP.stat
  122.              if rez = 0 then do
  123.  
  124.                 say " blt_DP.FD.fieldName is '"blt_DP.FD.fieldName"' (the following are for this)"
  125.                 say " blt_DP.fieldNumber is" blt_DP.fieldNumber
  126.                 say " blt_DP.fieldOffset is" blt_DP.fieldOffset
  127.                 say " blt_DP.FD.fieldType is '"blt_DP.FD.fieldType"'"
  128.                 say " blt_DP.FD.fieldLen is" blt_DP.FD.fieldLen
  129.                 say " blt_DP.FD.fieldDC is" blt_DP.FD.fieldDC
  130.  
  131.                 say
  132.                 say "calling blt_AddRecord(), 100 times"
  133.                 blt_AP.=NOVALUE
  134.                 blt_AP.handle = blt_OP.handle
  135.  
  136.                 /* generates SSN numbers from 465100001 to 465100100 */
  137.                 /* leading delete tag field (space) */
  138.                 /* NAME field just filled in with ... nothing important */
  139.                 /* this loop writes 100 records to disk */
  140.                 /* raw record is SSN(9), NAME(10), ADDR(10/memo number) */
  141.                 /* with the memo number in ADDR left empty */
  142.  
  143.                 do record = 100001 to 100100 until rez <> 0
  144.                    blt_AP.recData = " 465"record"name-nadaZ          "
  145.                    rez = blt_AddRecord()
  146.                 end
  147.                 say " blt_AP.func is" blt_AP.func
  148.                 say " blt_AP.stat is" blt_AP.stat
  149.                 if rez = 0 then do
  150.  
  151.                    tmpVar = record - 100001   /* record here is do limit +1 */
  152.                    say " Done writing the" tmpVar "test records"
  153.                    say
  154.                    say "calling blt_GetRecord()," tmpVar "times, unparsed output"
  155.                    blt_AP.=NOVALUE            /* always reset for demo purposes only */
  156.                    blt_AP.handle = blt_OP.handle
  157.                    blt_AP.recNo = 0
  158.                    do until rez <> 0
  159.                       blt_AP.recNo = blt_AP.recNo + 1
  160.                       rez = blt_GetRecord()
  161.                       if rez = 0 then do
  162.  
  163.                          say " rec#" blt_AP.recNo "'"blt_AP.recData"'"
  164.                          tmpVarStr = blt_AP.recData  /* save last valid data */
  165.                       end
  166.                    end
  167.  
  168.                    /* if read all records written, and result is 8609 */
  169.                    /* (expected) then okay */
  170.  
  171.                    if ((blt_AP.recNo-1) = tmpVar) & (blt_AP.stat = 8609) then do
  172.                       blt_AP.stat = 0
  173.                       rez = 0
  174.                    end
  175.                    say " blt_AP.func is" blt_AP.func
  176.                    say " blt_AP.stat is" blt_AP.stat
  177.                    if rez = 0 then do
  178.  
  179.                       /* non-index update of data record, see blt_Update() */
  180.                       /* for data+index updating */
  181.  
  182.                       tmpVar = blt_AP.recNo - 1  /* last valid rec# read, used again below */
  183.  
  184.                       say
  185.                       say "calling blt_UpdateRecord()  (update last record w/ new name)"
  186.                       blt_AP.=NOVALUE
  187.                       blt_AP.handle = blt_OP.handle
  188.                       blt_AP.recNo = tmpVar     /* last recNo, last data just read */
  189.                       blt_AP.recData = substr(tmpVarStr,1,10)"newnameXYZ          "
  190.                       rez = blt_UpdateRecord()
  191.                       say " blt_AP.func is" blt_AP.func
  192.                       say " blt_AP.stat is" blt_AP.stat
  193.                       if rez = 0 then do
  194.  
  195.                          /* blt_AP.handle and .recNo already set */
  196.                          say
  197.                          say "calling blt_GetRecord() on the updated record -- note newnameXYZ"
  198.                          rez = blt_GetRecord()
  199.                          if rez = 0 then do
  200.  
  201.                             say " rec#" blt_AP.recNo "'"blt_AP.recData"'"
  202.                             say
  203.                             say "calling blt_DeleteRecord() on first record, then"
  204.                             say "calling blt_UndeleteRecord() on first record, then"
  205.                             say "calling blt_DeleteRecord() on first record (again)"
  206.                             blt_AP.=NOVALUE
  207.                             blt_AP.handle = blt_OP.handle
  208.                             blt_AP.recNo = 1
  209.                             rez = blt_DeleteRecord()
  210.                             say " blt_AP.func is" blt_AP.func " (DeleteRecord)"
  211.                             say " blt_AP.stat is" blt_AP.stat
  212.  
  213.                             /* here the first record has had its delete */
  214.                             /* tag byte set to a * -- use blt_GetRecord() */
  215.                             /* to verify if you don't believe it */
  216.                             /* This does -not- physically remove the record */
  217.  
  218.                             if rez = 0 then do
  219.  
  220.                                rez = blt_UndeleteRecord()
  221.                                say " blt_AP.func is" blt_AP.func " (UndeleteRecord)"
  222.                                say " blt_AP.stat is" blt_AP.stat
  223.                                if rez = 0 then do
  224.  
  225.                                   rez = blt_DeleteRecord() /* for pack test */
  226.                                   say " blt_AP.func is" blt_AP.func " (DeleteRecord -second time)"
  227.                                   say " blt_AP.stat is" blt_AP.stat
  228.                                end
  229.                             end
  230.  
  231.                             /* slightly different flow ('end's above) just */
  232.                             /* to minimize indents, etc. */
  233.  
  234.                             if rez = 0 then do
  235.  
  236.                                say
  237.                                say "calling blt_DebumpRecord() (physical removal of last record)"
  238.                                blt_AP.=NOVALUE
  239.                                blt_AP.handle = blt_OP.handle
  240.                                blt_AP.recNo = tmpVar    /* tmpVar=last recNo set above */
  241.                                rez = blt_DebumpRecord()
  242.                                say " blt_AP.func is" blt_AP.func
  243.                                say " blt_AP.stat is" blt_AP.stat
  244.                                if rez = 0 then do
  245.  
  246.                                   say
  247.                                   say "calling blt_PackRecords() (removes records marked as deleted)"
  248.                                   blt_AP.=NOVALUE
  249.                                   blt_AP.handle = blt_OP.handle
  250.                                   rez = blt_PackRecords()
  251.                                   say " blt_AP.func is" blt_AP.func
  252.                                   say " blt_AP.stat is" blt_AP.stat
  253.                                   if rez = 0 then do
  254.  
  255.                                      say
  256.                                      say "Excellent!  All calls went as planned"
  257.                                   end
  258.                                   else do
  259.                                      say "* ERROR * blt_PackRecords()"
  260.                                   end
  261.  
  262.                                end
  263.                                else do
  264.                                   say "* ERROR * blt_DebumpRecord"
  265.                                end
  266.  
  267.                             end
  268.                             else do
  269.                                say "* ERROR * blt_DeleteRecord or UndeleteRecord()"
  270.                             end
  271.  
  272.                          end
  273.                          else do
  274.                             say "* ERROR * blt_GetRecord()"
  275.                          end
  276.  
  277.                       end
  278.                       else do
  279.                          say "* ERROR * blt_UpdateRecord()"
  280.                       end
  281.  
  282.                    end
  283.                    else do
  284.                       say "* ERROR * blt_GetRecord() at record"record+1
  285.                    end
  286.  
  287.                 end
  288.                 else do
  289.                    say "* ERROR * blt_AddRecord() at record"record
  290.                 end
  291.  
  292.              end
  293.              else do
  294.                 say "* ERROR * blt_GetDescriptor() [by fieldName]"
  295.              end
  296.  
  297.           end
  298.           else do
  299.              say "* ERROR * blt_GetDescriptor() [by fieldNumber]"
  300.           end
  301.  
  302.           /* if open, it's a good idea to close it (blt_Exit() will if not) */
  303.  
  304.           blt_HP.=NOVALUE
  305.           blt_HP.handle = blt_OP.handle
  306.           say
  307.           say "calling blt_CloseData()"
  308.           rez = blt_CloseData()
  309.           say " blt_HP.func is" blt_HP.func
  310.           say " blt_HP.stat is" blt_HP.stat
  311.  
  312.        end
  313.        else do
  314.           say "* ERROR * blt_OpenData()"
  315.        end
  316.  
  317.     end
  318.     else do
  319.        say
  320.        say "* ERROR * blt_CreateData()"
  321.     end
  322.  
  323.     say
  324.     say "calling blt_Exit()"
  325.     blt_EP.=NOVALUE
  326.     rez = blt_Exit()
  327.     say " blt_EP.func is" blt_EP.func
  328.     say " blt_EP.stat is" blt_EP.stat
  329.     say " blt_EP.rxAllocsLeft is" blt_EP.rxAllocsLeft
  330.  end
  331.  else do
  332.     say
  333.     say "* ERROR * blt_Init()"
  334.  end
  335.  
  336.  call BulletDropFuncs
  337.  exit 0
  338.